#ifndef __MDB_PLATFORM__
#define __MDB_PLATFORM__


#define USE_IN_TUYAOPEN			1
//lib use at lvgl
//#define USE_LVGL_UI				1


// port to special platform
#if (USE_IN_TUYAOPEN == 1)
#define 	mdb_mem_include			"tal_api.h"
#define		mdb_calloc 				tal_calloc
#define		mdb_free 				tal_free 
#define		MDB_MUTEX 				MUTEX_HANDLE
#define		mdb_lock_init(lock) 	tal_mutex_create_init(lock);
#define		_mdb_lock(lock) 		tal_mutex_lock(lock)
#define		_mdb_unlock(lock) 		tal_mutex_unlock(lock)

#define 	log_trace		PR_TRACE
#define 	log_debug		PR_DEBUG
#define 	log_info  		PR_INFO
#define 	log_warn		PR_WARN
#define 	log_error		PR_ERR

#else
#define 	mdb_mem_include			"<stdlib.h>"
#define		mdb_calloc 				calloc
#define		mdb_free 				free
#define		MDB_MUTEX 				pthread_mutex_t
#define		mdb_lock_init(lock) 	pthread_mutex_init(lock, NULL);
#define		_mdb_lock(lock) 		pthread_mutex_lock(lock)
#define		_mdb_unlock(lock) 		pthread_mutex_unlock(lock)

#endif

#include mdb_mem_include

#if 0
#define mdb_lock(lock) \
	do {\
		printf("[%s][%d]: db lock\n", __FUNCTION__, __LINE__);\
		_mdb_lock(lock);\
	} while(0)

#define mdb_unlock(lock) \
	do {\
		printf("[%s][%d]: db unlock\n", __FUNCTION__, __LINE__);\
		_mdb_unlock(lock);\
	} while(0)
#else
#define mdb_lock(lock) \
	do {\
		_mdb_lock(lock);\
	} while(0)

#define mdb_unlock(lock) \
	do {\
		_mdb_unlock(lock);\
	} while(0)
#endif


#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array)	(sizeof(array)/sizeof(array[0]))
#endif

#define DIV(a,b)	((b) != 0 ? (a) / (b) : (a))

#define CLIP(v,max,min)		(v = (v < min ? min : v > max ? max : v))
#define IN_RANGE(v,max,min)	(((v) >= (min)) && ((v) <= (max)))


#endif
